package show.lmm.invokeapp.core.client;

import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Component
public class TestAppClient {

    private final WebClient webClient;

    public TestAppClient(
            ReactorLoadBalancerExchangeFilterFunction lbFunction
    ) {
        this.webClient = WebClient.builder()
                .filter(lbFunction).build();
    }

    public Mono<String> getServerInfo(String info) {
        final String url = String.format("http://test-app/test/get/server_info?info=%s",info);
        return webClient.get().uri(url)
                .retrieve().bodyToMono(String.class);
    }
}
